package com.hdu.point_offer;

import com.sun.org.apache.regexp.internal.REUtil;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class lcr149 {


    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    class Solution {
        public int[] decorateRecord(TreeNode root) {
            if (root == null) return new int[0];
            Queue<TreeNode> q = new LinkedList<>();
            List<Integer> ans = new LinkedList<>();
            q.offer(root);
            while (!q.isEmpty())
            {
                int size = q.size();
                for (int i = 0; i < size; i++)
                {
                    TreeNode node = q.poll();
                    ans.add(node.val);
                    if (node.left != null) q.offer(node.left);
                    if (node.right != null) q.offer(node.right);
                }
            }
            int[] res = new int[ans.size()];
            for (int i = 0; i < ans.size(); i++)
            {
                res[i] = ans.get(i);
            }
            return res;
        }
    }
}
